package com.fqgj.xjd.user.dao.impl;

import com.fqgj.common.base.AbstractBaseMapper;
import com.fqgj.xjd.user.dao.UserBehaviorDeviceDao;
import com.fqgj.xjd.user.entity.UserBehaviorDeviceEntity;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.Map;

/**
 * User: zhangxingyun
 * Date: 2017-07-20
 * Time: 18:38:53.046
 */

@Repository
public class UserBehaviorDeviceDaoImpl extends AbstractBaseMapper<UserBehaviorDeviceEntity> implements UserBehaviorDeviceDao {

    @Override
    public UserBehaviorDeviceEntity selectLastOneByParams(Map<String, Object> params) {
        if (!params.containsKey("deleted")) {
            params.put("deleted", 0);
        }
        return getSqlSession().selectOne(getStatement("selectLastOneByParams"), params);
    }

    @Override
    public UserBehaviorDeviceEntity selectDeviceByUserCode(String userCode) {
        Map<String, Object> params = new HashMap<>();
        params.put("userCode", userCode);
        return this.selectLastOneByParams(params);
    }

    /**
     * @param clientId
     * @return
     */
    @Override
    public UserBehaviorDeviceEntity selectDeviceByClientId(String clientId) {
        Map<String, Object> params = new HashMap<>();
        params.put("clientId", clientId);
        return this.selectLastOneByParams(params);
    }

    @Override
    public UserBehaviorDeviceEntity selectDeviceByUserCodeAndClientId(String userCode, String clientId) {
        Map<String, Object> params = new HashMap<>();
        params.put("userCode", userCode);
        params.put("clientId", clientId);
        return this.selectLastOneByParams(params);
    }
}
